package cn.buk.tms.eotms.dao;

import cn.buk.tms.eotms.entity.Airport;
import org.springframework.stereotype.Component;

import jakarta.persistence.EntityManager;
import jakarta.transaction.Transactional;
import java.util.List;

/**
 *
 * @author yfdai
 * @date 2015-3-19
 */
@Component
@Transactional
public class BasicDataDaoImpl extends AbstractDao implements BasicDataDao {

    private Airport getAirport(String threeCode, EntityManager em) {
        List<Airport> list = em.createQuery("select o from Airport o where o.threeCode = :code", Airport.class)
                .setParameter("code", threeCode).getResultList();

        return list.size() == 0 ? null : list.get(0);
    }

    @Override
    public Airport getAirport(String threeCode) {
        if (threeCode == null) {
          return null;
        }

        return getAirport(threeCode, em);
    }

}
